/**
 * @Copyright (c) 2006,东登信息网络有限公司
 * @All rights reserved.
 *
 * 用于Ajax读取数据显示 || 直接显示数据 || 显示图片
 * 如果使用ajax,需要加载DAjax类,只用户读取某个页面内容
 * 如果使用效果,需要加载Effect
 * 如果使用拖动,需要加载DragDrop
 *
 * @file_name   LightBox.js
 * @version     1.0
 * @author      黄新泽
 * @date        2007-10-08 16:09:40
 */

/**
 * Class and Function List:
 * Function list:
 * - initialize: function()
 * - addLightboxMarkup: function(s)
 * - activate: function()
 * - prepareIE: function(height, overflow)
 * - hideSelects: function(visibility)
 * - getScroll: function()
 * - setScroll: function(x, y)
 * - displayLightbox: function(display)
 * - loadInfo: function(url, arg)
 * - responseData : function(response, ajaxObj)
 * - processInfo: function(response, type)
 * - function resizeLightBox()
 * - actions: function()
 * - insert: function(e)
 * - deactivate: function()
 * - remove: function()
 * - tag: function(ctrl)
 * - doTag : function(event)
 * - function initialize()
 * Classes list:
 * - .LightBox
 */

document.write('<div   id="tooltip_singleton"  class="singleton" style="z-index:6000;display:none;"><div><table cellpadding="0" cellspacing="0" style="float:left;"><tr><td id="tooltip_singleton_cts"><div style="float:left; border:1px solid #0a0a08; background:#41413f; padding:1px;"><div style="float:left; border:1px solid #0a0a08; background:url(' + IMA_PATH + '/main/jz_a_2.gif) no-repeat bottom; padding:4px; color:#d4d691;" id="tooltip_singleton_cts_text"></div></div></td></tr></table></div></div>');

var LightBox = Class.create();

LightBox.prototype = {

	yPos : 0,
	xPos : 0,
	box : {id:0, zIndex:500, tId:0},
	ajaxObj : [],
	ajaxId : 0,
	imageId : 0,
	eb :{eid:0},
	cTOption :{click:[], dblClick:[]},

	cOption :{click:[], dblClick:[]},
	maxOption :{click:[], dblClick:[]},
	minOption :{click:[], dblClick:[]},
	titleOption :{click:[], dblClick:[]},

	restoreData : [{}],
	restoreTData : [{}],
	maxStyle : {top:"0px", left:"0px", width:"100%", height:"100%", borderLeftWidth:"0px", borderRightWidth:"0px", borderTopWidth:"0px", borderBottomWidth:"0px"},
	minStyle : {top:"0px", left:"10px", width:"150px", height:"auto"},

	tooltipSingleton : [],
	empty : function(){return false;},

	/**
	 * 构造函数
	 *
	 * @access	public
	 */
	initialize: function()
	{
		++ this.eb.eid;
//		var bod			= document.getElementsByTagName('body')[0];
//
//		//可以根据style调用lightbox 样式类来生成box
//		var tooltip		= document.createElement('div');
//		tooltip.id		= 'tooltip_singleton'
//		tooltip.className 	= 'singleton ';
//		tooltip.style.zIndex = 6000 ;
//		tooltip.style.display = 'none' ;
//		tooltip.innerHTML = '<table cellpadding="0" cellspacing="0" style="float:left;"><tr><td id="tooltip_singleton_cts"></td></tr></table>';
//		bod.appendChild(tooltip);
//
//		//'undefined' == typeof(Draggable) ? null : new Draggable('tooltip0');
//		Element.hide('tooltip_singleton');

	},

	/**
	 * 生成遮罩,此处没有定义高度,宽度.放在最后显示处定义.
	 *
	 *	<div id="overlay1" class="overlay" style="z-index: 501;"/>
	 *	<div id="lightbox1" class="lightbox loading" style="z-index: 502;">
	 *		<div class="title" id="title1"/>
	 *		<a href="javascript:;" title= "点击最小" id="min" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>
	 *		<a href="javascript:;" title= "点击放大" id="max" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>
	 *		<a href="javascript:;" title= "点击关闭" id="c" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a>
	 *		<div style="z-index: 502;" class="lbContainer" id="lbContainer1">
	 *			<div class="contents" id="contents1"/>
	 *		</div>
	 *		<div class="lbLoadMessage" id="lbLoadMessage1" style="display: none;"><img src="' + IMA_PATH + '/js/loading2.gif"/></div>
	 *	</div>
	 * @param Int	s	overlay styoe
	 * @access	public
	 */
	addLightboxMarkup: function(s)
	{
		this.box.id ++ ;
		this.box.zIndex ++ ;
		var bod			= document.getElementsByTagName('body')[0];

		//生成遮罩
		var overlay		= document.createElement('div');
		overlay.id		= 'overlay' + this.box.id;
		overlay.className 	= 'overlay';
		overlay.style.zIndex = this.box.zIndex ;

		var pg = getPageSize();
		overlay.style.height = pg[1] + 'px'; ;

		//生成lightbox
		this.box.zIndex ++ ;
		var lb			= document.createElement('div');
		lb.id			= 'lightbox' + this.box.id;
		lb.className 	= 'lightbox loading';
		lb.style.zIndex = this.box.zIndex;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<div id="title' + this.box.id + '"  class="title" style="display:none;"><div><span id="tc' + this.box.id + '" class="title_text">&nbsp;</span>\
							<a href="javascript:;" title= "点击最小" id="min' + this.box.id + '" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>\
							<a href="javascript:;" title= "点击放大" id="max' + this.box.id + '" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>\
							<a href="javascript:;" title= "点击关闭" id="c' + this.box.id + '" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a></div></div>\
							<div id="lbContainer' + this.box.id + '" class="lbContainer" style="z-index:' + this.box.zIndex + '">\
								<div  id="contents' + this.box.id + '" class="contents"><table  style="width:100%;height:100%;text-align: center;"  id="lbTbale' + this.box.id + '" ><tr><td><table  style="width:1%;height:1%;text-align: center;" align="center" ><tr><td id="contents_table' + this.box.id + '"></td></tr></table></td></tr></table></div>\
							</div>\
							<div id="lbLoadMessage' + this.box.id + '"  class="lbLoadMessage">' + '<img src="' + IMA_PATH + '/js/loading2.gif">' + '</div>\
							<div id="bottom' + this.box.id + '"  class="bottom"></div>';
		lb.innerHTML	= style_contents;
		bod.appendChild(overlay);
		bod.appendChild(lb);

//		this.cOption.click[this.box.id] = this.remove.bindAsEventListener(this);
//		this.maxOption.click[this.box.id] = this.max.bindAsEventListener(this);
//		this.minOption.click[this.box.id] = this.min.bindAsEventListener(this);
//		this.titleOption.dblClick[this.box.id] = this.max.bindAsEventListener(this);
//
//		Event.observe($('c' + this.box.id), 'click', this.cOption.click[this.box.id], false);
//		Event.observe($('max' + this.box.id), 'click', this.maxOption.click[this.box.id], false);
//		Event.observe($('min' + this.box.id), 'click', this.minOption.click[this.box.id], false);
//		Event.observe($('title' + this.box.id), 'dblclick', this.titleOption.dblClick[this.box.id], false);
//
//		$('c' + this.box.id).onclick = $('max' + this.box.id).onclick = $('min' + this.box.id).onclick = $('title' + this.box.id).onclick = this.empty;

		bod = null;
		pg = null;
		style_contents = null;
		overlay = null;
		lb = null;

		Element.hide('lbLoadMessage' + this.box.id ); //屏蔽默认显示加载框,什么都不显示,需要加载的,单独打开
	},



	addWindow: function(event, option)
	{
		this.box.tId ++ ;
		this.box.zIndex += 2  ;

		var bod			= document.getElementsByTagName('body')[0];

		//可以根据style调用lightbox 样式类来生成box
		var tooltip		= document.createElement('div');
		tooltip.id		= 'tooltip' + this.box.tId;
		tooltip.className 	= 'tooltip';
		tooltip.style.zIndex = this.box.zIndex ;
		tooltip.style.top = option.x + 'px';
		tooltip.style.left = option.y + 'px';

		// old
		var style_contents = '<a href="javascript:;" title= "点击关闭"  id="ct' + this.box.tId + '"  class="lb_close" >\
								<img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭">\
							</a>\
							<div id="tooltip_cts' + this.box.tId + '" class="tooltip_cts"/>';


		 style_contents = '<div id="titlet' + this.box.tId + '"  class="title">&nbsp;' + option.t + '</div>\
							<a href="javascript:;" title= "点击最小" id="mint' + this.box.tId + '" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>\
							<a href="javascript:;" title= "点击放大" id="maxt' + this.box.tId + '" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>\
							<a href="javascript:;" title= "点击关闭" id="ct' + this.box.tId + '" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a>\
							<div id="tooltip_cts' + this.box.tId + '" class="tooltip_cts" style="z-index:' + this.box.zIndex + '">\
							</div>\
							<div id="bottom' + this.box.tId + '"  class="bottom"></div>';

		tooltip.innerHTML = style_contents;
		bod.appendChild(tooltip);
		Element.show(tooltip);

//		this.cOption.click[this.box.tId] = this.hideTagT.bindAsEventListener(this);
//		this.maxOption.click[this.box.tId] = this.maxT.bindAsEventListener(this);
//		this.minOption.click[this.box.tId] = this.minT.bindAsEventListener(this);
//		this.titleOption.dblClick[this.box.tId] = this.maxT.bindAsEventListener(this);
//
//		Event.observe('ct' + this.box.tId, 'click', this.cOption.click[this.box.tId], false);
//		Event.observe('maxt' + this.box.tId, 'click', this.maxOption.click[this.box.tId], false);
//		Event.observe('mint' + this.box.tId, 'click', this.minOption.click[this.box.tId], false);
//		Event.observe('titlet' + this.box.tId, 'dblclick', this.titleOption.dblClick[this.box.tId], false);
//
//		$('ct' + this.box.tId).onclick = this.empty;
//		$('maxt' + this.box.tId).onclick = this.empty;
//		$('mint' + this.box.tId).onclick = this.empty;
//		$('titlet' + this.box.tId).onclick = this.empty;
//		'undefined' == typeof(Draggable) ? null : new Draggable('tooltip' + this.box.tId, {handle:'titlet' + this.box.tId});
//		
		tooltip = null;
		this.prepareIE('100%', 'hidden');
	},


	addHelpWindow: function(s)
	{
		var bod			= document.getElementsByTagName('body')[0];

		//生成lightbox

		var lb			= document.createElement('div');
		lb.id			= 'lightbox_help';
		lb.className 	= 'lightbox loading no_scroll';
		lb.style.zIndex = 499;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<!--div id="title_help"  class="title"><div><span id="tc_help" class="title_text">&nbsp;</span>\
							<a href="javascript:;" title= "点击最小" id="min_help" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>\
							<a href="javascript:;" title= "点击放大" id="max_help" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>\
							</div></div-->\
							<a href="javascript:;" title= "点击关闭" id="c_help" class="lb_close"  onclick="Element.hide(\'lightbox_help\')"><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a>\
							<div id="lbContainer_help" class="lbContainer no_scroll" style="z-index:' + this.box.zIndex + '">\
								<div  id="contents_help" class="contents no_scroll"><iframe class="help_iframe" id="help_url"  width="100%" height="524" frameborder="0" scrolling="no" src="javascript:false;" style="background:transparent;" ></iframe></div>\
							</div>\
							<div id="lbLoadMessage_help"  class="lbLoadMessage">' + '<img src="' + IMA_PATH + '/js/loading2.gif">' + '</div>\
							<div id="bottom_help"  class="bottom"></div>';
		lb.innerHTML	= style_contents;

		bod.appendChild(lb);

//		this.cOption.click[this.box.id] = this.remove.bindAsEventListener(this);
//		this.maxOption.click[this.box.id] = this.max.bindAsEventListener(this);
//		this.minOption.click[this.box.id] = this.min.bindAsEventListener(this);
//		this.titleOption.dblClick[this.box.id] = this.max.bindAsEventListener(this);
//
//		Event.observe($('c' + this.box.id), 'click', this.cOption.click[this.box.id], false);
//		Event.observe($('max' + this.box.id), 'click', this.maxOption.click[this.box.id], false);
//		Event.observe($('min' + this.box.id), 'click', this.minOption.click[this.box.id], false);
//		Event.observe($('title' + this.box.id), 'dblclick', this.titleOption.dblClick[this.box.id], false);
//
//		$('c' + this.box.id).onclick = $('max' + this.box.id).onclick = $('min' + this.box.id).onclick = $('title' + this.box.id).onclick = this.empty;

		bod = null;
		style_contents = null;
		lb = null;

		Element.hide('lbLoadMessage_help'); //屏蔽默认显示加载框,什么都不显示,需要加载的,单独打开
		console.info('生成帮助窗口');

		'undefined' == typeof(Draggable) ? null : new Draggable('lightbox_help');
	},


	addMsgWindow: function(s)
	{
		this.box.zIndex ++ ;

		var bod			= document.getElementsByTagName('body')[0];

		//生成遮罩
		var overlay		= document.createElement('div');
		overlay.id		= 'overlay_msg';
		overlay.className 	= 'overlay';
		overlay.style.zIndex =  this.box.zIndex ;

		var pg = getPageSize();
		overlay.style.height = pg[1] + 'px'; ;

		//生成lightbox
		this.box.zIndex ++ ;
		var lb			= document.createElement('div');
		lb.id			= 'lightbox_msg';
		lb.className 	= 'lightbox loading';
		lb.style.zIndex =  this.box.zIndex;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<div id="lbContainer_msg" class="lbContainer" style="z-index:50001">\
								<div  id="contents_msg" class="contents"><table  style="width:100%;height:100%;text-align: center;"  id="lbTbale_msg" ><tr><td><table  style="width:1%;height:1%;text-align: center;" align="center" ><tr><td id="contents_table_msg"></td></tr></table></td></tr></table></div>\
							</div>\
							<div id="lbLoadMessage_msg"  class="lbLoadMessage"><img src="' + IMA_PATH + '/js/loading2.gif" /></div>\
							<div id="bottom_msg"  class="bottom"></div>';
		lb.innerHTML	= style_contents;
		bod.appendChild(overlay);
		bod.appendChild(lb);

		bod = null;
		pg = null;
		style_contents = null;
		overlay = null;
		lb = null;

		Element.show('lbLoadMessage_msg');

		var lb = $('lightbox_msg');
		var lct =$('lbContainer_msg');
		var ct = $('contents_msg');

		var w=100;
		var h=100;

		var arrayPageScroll = getPageSize();
		var lightboxTop = ((arrayPageSize[3] - 35 - h) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);

		if (Prototype.Browser.IE && !Prototype.Browser.IE7)
		{
			Position.prepare();
			lightboxTop += Position.deltaY;
		}

		lct.style.width = w + "px";
		lct.style.height = h + "px";

		lb.style.width = w + "px";
		lb.style.height = h + "px";
		lb.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		lb.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		lb.style.margin = '0px';

		this.prepareIE('100%', 'hidden');
	},


	/**
	 * 返回提示消息框
	 *
	 * @access	public
	 */
	getMsgBox: function(c, w)
	{
		var msgBox = '\
				<div class="lightbox_msg">\
					<div class="lightbox_msg_bg">\
						<div class="lightbox_msg_contents">\
							<ul>\
								<li style="text-align:center;color:#c7bec3;" class="msg_box_text">#{msg}</li>\
								<li style="text-align:center;"> &nbsp;</li>';
		if (c)
		{
					msgBox += '<li style="text-align:center;"><img src="' + IMA_PATH + '/main/jz_b_6.gif" rel="remove" class="lbAction" /></li>';
		}

					msgBox += '</ul>\
								</div>\
							</div>\
						</div>\
						';

//		var msgBox = '\
//		<div class="lightbox_msg">\
//				<div class="kj_c_a">\
//					<ul>\
//						<li class="kj_c_b"><table style="width:100%;height:100%;text-align: center;" align="center" ><tr><td valign="middle">#{msg}</td></tr></table></li>';
//		if (c)
//		{
//					msgBox += '<li class="kj_c_c"><img src="' + IMA_PATH + '/js/zz_a_c.gif"   rel="remove" class="lbAction" /></li>';
//		}
//					msgBox += '\
//					</ul>\
//				</div>\
//		</div>\
//						';

		return msgBox;
	},

	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	showMsgBox: function(msg_contents, c, t, w)
	{
		this.getMsgBox(c, w);
		var tpl = new Template(this.getMsgBox(c, w));
		var msg = {msg:msg_contents};

		var msg_box = tpl.evaluate(msg);

		if (!t)
		{
			t = 'n';
		}

		msg_contents = c = t = w = null;
		msg = null;
		tpl = null;

		return mask.processInfo(msg_box, t);
	},


	/**
	 * Turn everything on - 调整IE问题
	 *
	 * @access	public
	 */
	activate: function()
	{
		if (Prototype.Browser.IE)
		{
			//this.getScroll();
			this.prepareIE('100%', 'hidden');
			//this.setScroll(0, 0);
			this.hideSelects('hidden');
		}

		this.displayLightbox("block");
	},

	/**
	 * Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	 *
	 * @param Int		height		Body 高度
	 * @param String	overflow	Body overflow
	 *
	 * @access	public
	 */
	prepareIE: function(height, overflow)
	{
		var bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		//bod.style.overflow = overflow;

		var htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		//htm.style.overflow = overflow;

		bod = null;
		htm = null;
	},

	/**
	 * 解决Ie  select 控件z-index总是最高bug
	 *
	 * @param String	visibility	style.display
	 *
	 * @access	public
	 */
	hideSelects: function(visibility)
	{
		var selects = null;

		//显示隐藏问题
		if ('hidden' == visibility)
		{
			if (1 == this.box.id)
			{
				selects = document.getElementsByTagName('select');
			}
			else
			{
				var i = this.box.id - 1 ;
				selects = $('lightbox' + i).getElementsByTagName('select');
			}
		}
		else
		{
			if (1 == this.box.id)
			{
				selects = document.getElementsByTagName('select');
			}
			else
			{
				var i = this.box.id - 1 ;
				selects = $('lightbox' + i).getElementsByTagName('select');
			}
		}


		for(i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility = visibility;
		}

		selects = null;
	},

	/**
	 * 处理滚动条
	 *
	 * @access	public
	 */
	getScroll: function()
	{
		Position.prepare();
		this.yPos = Position.deltaY;
	},

	/**
	 * 重新设置滚动位置
	 *
	 * @access	public
	 */
	setScroll: function(x, y)
	{
		window.scrollTo(x, y);
	},

	/**
	 * 显示还是隐藏控件
	 *
	 * @param String	display	style.display
	 *
	 * @access	public
	 */
	displayLightbox: function(display)
	{
		$('overlay' + this.box.id).style.display = display;
		$('lightbox' + this.box.id).style.display = display;
	},

	// Begin Ajax request based off of the href of the clicked linked
	// Display Ajax response or text
	/**
		arg = {
			text:'msg',
			type:'n' or 'o'
			method: 'post',
			parameters: ""
		}
	*/
	/**
	 * DAjax取得数据
	 *
	 * @param String	url		请求地址
	 * @param Object	arg		请求附带的参数
	 *
	 * @access	public
	 */
	loadInfo: function(url, arg)
	{
		if (!url)
		{
			return false;
		}

		var option = {option:{onSuccess:this.responseData.bind(this), lbType:'n' }, logic:{type:"e"}};
		Object.extend(option, arg);
		this.ajaxId ++ ;


		//DHistory.add('mask.loadInfo_' + url , arguments);


		option.option.onSuccess = this.responseData.bind(this);

		//可以判断类是否初始化,暂时没有判断, ( 消息机制错乱,问题严重,可能用法取消,或者重新编码解决) -> 已经解决
		this.ajaxObj[this.ajaxId] = new DAjax(url, option);
		this.ajaxObj[this.ajaxId].sendRequest();

		option = null;
		url = null;
	},

	/**
	 * 处理DAjax返回数据
	 *
	 * @param Object	response	response
	 * @param Object	ajaxObj		DAjax句柄
	 *
	 * @access	public
	 */
	responseData : function(response, ajaxObj)
	{
		this.processInfo(response.responseText, ajaxObj.lbType);
		this.ajaxObj[this.ajaxId] = null;
		this.ajaxId --;

		response = null;
		ajaxObj.msg.removeMessage();
		ajaxObj.collectCarbage();

		ajaxObj = null;
	},

	/**
	 * 显示数据
	 *
	 * @param Object	response	response
	 * @param String	type		显示类型
	 * @param String	title		显示标题
	 *
	 * type == t , tooltip                
	 * type == n , 生成新box内容信息  == new 
	 * type == o , 覆盖当前box内容信息 == old 
	 * type == i , image, type相当于 new    
	 * 
	 * @access	public
	 */
	processInfo: function(response, type, title)
	{
		if ('t' == type)
		{
			//未和id绑定,会导致错乱
			Element.show('tooltip' + this.box.tId);
			$('tooltip_cts' + this.box.tId).update(response);
			this.actions($('tooltip_cts' + this.box.tId));

			response = null;
			return false;
		}

		//窗口默认大小
		var w = 1000;
		var h = 620;
//console.info((new	Date()).getTime());
		//因为有覆盖问题,所以.. ..
		if ('o' == type)
		{
			if (!this.box.id)
			{
				type = 'n';
				this.addLightboxMarkup();
				this.activate();
			}
		}
		else
		{
			this.addLightboxMarkup();
			this.activate();
		}

		$('tc' + this.box.id).update(title);

//console.info((new	Date()).getTime());

		var lb = $('lightbox' + this.box.id);
		var lct =$('lbContainer' + this.box.id);
		var ct = $('contents' + this.box.id);
		var ctt = $('contents_table' + this.box.id);
		var ctable = $('lbTbale' + this.box.id);

		if ('o' == type)
		{
			ctt.update(response);
			//new Insertion.Top(ctt, '<div  class="sg_jz_b_bg_new"><img src="' + IMA_PATH + '/main/jz_b_6.gif" rel="remove" class="lbAction" style="float:right;"  /></div>');

			resizeLightBox();
		}
		else
		{
			//如果是图片
			if ('i' == type)
			{
				w = h = 100;

				resizeLightBox();
				//打开加载显示框
				Element.show('lbLoadMessage' + this.box.id );

				//prototype_1.6.0_rc0.js  降低到prototype_1.5.1.js bug 解决
				//var objImage = document.createElement("img");
				//objImage.setAttribute('id','lightboxImage' + this.box.id);
				var objImage = '<img id="lightboxImage' + this.box.id +'" border="0" />';

				lct.style.overflow = 'visible' ;
				ctt.update(objImage);

				objImage = $('lightboxImage' + this.box.id);

				//点击关闭
				Event.observe(objImage, 'click', this.remove.bind(this), false);

				// preload image
				imgPreload = new Image();

				imgPreload.onload=function()
				{
					objImage.src = response;
					// center lightbox and make sure that the top and left values are not negative
					// and the image placed outside the viewport
					w = imgPreload.width;
					h = imgPreload.height;

					ct.style.width = w + "px";
					ct.style.height = h + "px";

					// A small pause between the image loading and displaying is required with IE,
					// this prevents the previous image displaying for a short burst causing flicker.
					if (Prototype.Browser.IE)
					{
						//pause(250);
						//pause(25);
					}

					imgPreload.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

					resizeLightBox();
					lb.removeClassName("loading");
					response = null;
					return false;
				};

				imgPreload.src = response;
			}
			else
			{
				ctt.update(response);
				//new Insertion.Top(ctt, '<div  class="sg_jz_b_bg_new"><img src="' + IMA_PATH + '/main/jz_b_6.gif" rel="remove" class="lbAction" style="float:right;"  /></div>');


				resizeLightBox();
				lb.removeClassName("loading");
			}

			//Effect.Appear($('overlay' + this.box.id), {to: 0.5, from: 0.0});

			Element.show($('overlay' + this.box.id));
			lb.addClassName("done");
		}

		//效果
		//Effect.Grow('lbContainer' + this.box.id,{});
		//Effect.SlideDown(lct,{});
		if('undefined' != typeof(Effect))
		{
			//Effect.Grow(lct,{duration:2.0});
		}

		function resizeLightBox()
		{
			var arrayPageScroll = getPageSize();
			var lightboxTop = ((arrayPageSize[3] - 35 - h) / 2);
			var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);

			if (Prototype.Browser.IE && !Prototype.Browser.IE7)
			{
				Position.prepare();
				lightboxTop += Position.deltaY;
			}

			
			ctable.style.width = w + "px";
			ctable.style.height = h + "px";



			ct.style.width = w + "px";
			ct.style.height = h + "px";

			lct.style.width = w + "px";
			lct.style.height = h + "px";

			lb.style.width = w + "px";
			lb.style.height = h + "px";
			lb.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
			lb.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
			lb.style.margin = '0px';
		}

		//resize('lbContainer' + this.box.id, 'contents' + this.box.id);
		//如果ajax取得数据,取回的数据是否要处理?
		this.actions(lb);
//console.info((new	Date()).getTime());
		if('undefined' != typeof(Effect))
		{
			//Effect.SlideDown('title' + this.box.id,{duration:1.0});
		}

		Element.hide('title' + this.box.id);
		//setTimeout("mask.drag()", 1000);

		response = null;
		lb = null;
		lct = null;
		ct = null;
		ctt = null;
		ctable = null;

		return this.box.id;
	},

	/**
	 * 
	 *
	 * @access	public
	 */
	drag: function()
	{
		try
		{
			//拖动
			if('undefined' != typeof(Draggable))
			{
				new Draggable($('lightbox' + this.box.id), {handle:'title' + this.box.id});
			}
		}
		catch(e)
		{}
	},

	/**
	 * 添加事件 Search through new links within the lightbox, and attach click event
	 * 
	 * @access	public
	 */
	actions: function(id)
	{
		var lbActions = $(id).getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++)
		{
			//Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
			Event.observe(lbActions[i], 'click', this[lbActions[i].getAttribute('rel')].bind(this), false);
			lbActions[i].onclick = this.empty;
		}
		lbActions = null;

		var lbox = $(id).getElementsByClassName('O');

		for(i = 0; i < lbox.length; i++)
		{
			mask.tag(lbox[i]);
		}
		lbox = null;

		//处理tooltip
		lbox = $(id).getElementsByClassName('T');

		for(i = 0; i < lbox.length; i++)
		{
			mask.tagT(lbox[i]);
		}

		lbox = $(id).getElementsByClassName('TS');

		for(i = 0; i < lbox.length; i++)
		{
			mask.tagTS(lbox[i]);
		}

		lbox = null;

	},

	/**
	 * 用于解决内存泄漏问题,暂时不处理.
	 *
	 * @access	public
	 */
	deActions: function()
	{
		this.restoreData[this.box.id] = false;
	},

	/**
	 * 用于解决内存泄漏问题,暂时不处理.
	 *
	 * @access	public
	 */
	deEvent: function(id)
	{
		var lbActions = $(id).getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++)
		{
			lbActions[i].stopObserving('click');
		}

		lbActions = null;

		var lbox = $(id).getElementsByClassName('O');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
		}
		lbox = null;

		//处理tooltip
		lbox = $(id).getElementsByClassName('T');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
		}

		lbox = $(id).getElementsByClassName('TS');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
			lbox[i].stopObserving('mouseover');
			lbox[i].stopObserving('mouseout');
			lbox[i].stopObserving('mousemove');
			lbox[i].stopObserving('blur');
		}

		lbox = null;
	},

	/**
	 * 处理自定义函数.
	 *
	 * @access	public
	 */
	insert: function(e)
	{
		var link = Event.element(e).parentNode;
		var type = 'n';

		if (isSet(link.type))
		{
			type = link.type;
		}

		this.loadInfo(link.href, {option:{lbType:type}});
	},

	/**
	 * 处理自定义函数.
	 *
	 * @access	public
	 */
	deactivate: function(e)
	{
		this.remove(e);
	},

	/**
	 * @access	public
	 */
	remove: function(e)
	{

		try 
		{
			if (intVal(this.box.id))
			{
				this.deEvent($('overlay' + this.box.id));
				this.deEvent($('lightbox' + this.box.id));

				this.deActions();
				Element.remove($('overlay' + this.box.id));
				Element.remove($('lightbox' + this.box.id));

				if (Prototype.Browser.IE)
				{
					if (1 == this.box.id)
					{
						this.prepareIE("auto", "auto");
					}

					this.hideSelects("visible");
					//this.setScroll(0, this.yPos);
				}

				this.box.id --;
				this.box.zIndex = this.box.zIndex -2  ;
				//this.displayLightbox("none");
			}
		}
		catch(e)
		{}

		return false;
	},

	/**
	 * @access	public
	 */
	removeMsg: function(e)
	{

		try 
		{
				Element.remove($('overlay_msg'));
				Element.remove($('lightbox_msg'));

				if (Prototype.Browser.IE)
				{
					if (1 == this.box.id)
					{
						this.prepareIE("auto", "auto");
					}

					this.hideSelects("visible");
					//this.setScroll(0, this.yPos);
				}

				this.box.zIndex = this.box.zIndex -2  ;
		}
		catch(e)
		{}

		return false;
	},

	/**
	 * @access	public
	 */
	removeById: function(id)
	{
		if (intVal(this.box.id) == id)
		{
			this.remove();
		}

		return false;
	},

	/**
	 * @access	public
	 */
	setRestoreData: function(lb)
	{
		var currentStyle = {};
		['top', 'left', 'width', 'height', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'].each(function(s) {currentStyle[s] = lb.getStyle(s)});

		if (!this.restoreData[this.box.id])
		{
			this.restoreData[this.box.id] = currentStyle;
		}

		return currentStyle;
	},

	/**
	 * @access	public
	 */
	max: function()
	{
		
		Element.show('lbContainer' + this.box.id);
		var lb = $('lightbox' + this.box.id);

		var currentStyle = this.setRestoreData(lb);;

		if (!this.restoreData[this.box.id])
		{
			this.restoreData[this.box.id] = currentStyle;
		}

		if (Object.toJSON(currentStyle)!=Object.toJSON(this.maxStyle))
		{
			lb.setStyle(this.maxStyle);
			this.getScroll();
			this.setScroll(0, 0);
			
		}
		else
		{
			lb.setStyle(this.restoreData[this.box.id]);
			this.setScroll(0, this.yPos);
		}

		//resize('lbContainer' + this.box.id, 'contents' + this.box.id);
		//resizeBodyText('lbContainer' + this.box.id, 'contents' + this.box.id);
		return false;
	},

	/**
	 * @access	public
	 */
	restore: function()
	{
	},

	/**
	 * @access	public
	 */
	min: function()
	{
		Element.hide('lbContainer' + this.box.id);
		var lb = $('lightbox' + this.box.id);
		this.setRestoreData(lb);

		lb.setStyle(this.minStyle);
		return false;
	},

	/**
	 * 处理LightBox.
	 *
	 * @access	public
	 */
	tag: function(ctrl)
	{
		this.content = ctrl.href;
		Event.observe(ctrl, 'click', this.doTag.bind(this), false);
		ctrl.onclick = this.empty;
	},

	doTag : function(event)
	{
		//触发事件bug问题
		var elt = Event.element(event);
		
		//var elt = Event.findElement(event, 'A');  如下可兼容非A标签
		if ('O' != elt.className)
		{
			elt = elt.up('.O');
		}

		var matchPic = new RegExp("^(http|https|ftp|mms|rtsp)://[A-Za-z0-9\./=\?%_~@#:;\+\-]*[\.]+(gif|jpg|png)+$", "ig");
		if(matchPic.test(elt.href))
		{
			this.processInfo(elt.href, 'i');
		}
		else
		{
			this.loadInfo(elt.href, {option:{lbType:'n'}});
		}
	},

	tooltip: function(response, type)
	{
	},
	
	/**
	 * 处理Tooltip.
	 *
	 * @access	public
	 */
	tagT: function(ctrl)
	{
		this.content = ctrl.href;
		Event.observe(ctrl, 'click', this.doTagT.bind(this), false);
		//Event.observe(ctrl, 'mouseout', this.hideTagT.bindAsEventListener(this), false);
		ctrl.onmouseover = this.empty;
		ctrl.onclick = this.empty;
	},

	hideTagT : function(event)
	{
		//触发事件bug问题
		var elt = Event.element(event);
		
		if ('lb_close' != elt.className)
		{
			elt = elt.up('.lb_close');
		}
		var id = elt.id.substr(2);

		this.box.zIndex -= 2  ;
		Element.hide('tooltip' + id);
	},

	/**
	 * @access	public
	 */
	setRestoreTData: function(t)
	{
		var currentStyle = {};
		['top', 'left', 'width', 'height', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'].each(function(s) {currentStyle[s] = t.getStyle(s)});

		if (!this.restoreTData[t.id])
		{
			this.restoreTData[t.id] = currentStyle;
		}

		return currentStyle;
	},

	/**
	 * @access	public
	 */
	maxT: function(e)
	{
		//触发事件bug问题
		var elt = Event.element(e);
		var id =  null;

		if ('title' == elt.className)
		{
			id = elt.id.substr(6);
		}
		else if ('lb_max' != elt.className)
		{
			elt = elt.up('.lb_max');
			id = elt.id.substr(4);
		}

		Element.show($('tooltip_cts' + id));
		var t = $('tooltip' + id);

		var currentStyle = this.setRestoreTData(t);

		if (!this.restoreTData[t.id])
		{
			this.restoreTData[t.id] = currentStyle;
		}

		if (Object.toJSON(currentStyle)!=Object.toJSON(this.maxStyle))
		{
			t.setStyle(this.maxStyle);
			this.getScroll();
			this.setScroll(0, 0);
		}
		else
		{
			t.setStyle(this.restoreTData[t.id]);
			
			this.setScroll(0, this.yPos);
		}

		return false;
	},


	/**
	 * @access	public
	 */
	minT: function(e)
	{
		//触发事件bug问题
		var elt = Event.element(e);
		
		if ('lb_min' != elt.className)
		{
			elt = elt.up('.lb_min');
		}

		var id = elt.id.substr(4);
		var t = $('tooltip' + id);

		this.setRestoreTData(t);
		Element.hide($('tooltip_cts' + id));

		this.setRestoreData(t);

		t.setStyle(this.minStyle);
		return false;

	},

	doTagT : function(event)
	{
		var defaults = {t:"", c:""};
		var options = {};
		var elt = Event.element(event);

		if (!arguments[1])
		{
			if ('T' != elt.className)
			{
				elt = elt.up('.T');
			}

			options.t = elt.innerHTML.escapeHTML();

			if (elt.getAttribute('msg'))
			{
				options.c = elt.getAttribute('msg');
			}
			else
			{
				options.c = elt.getAttribute('title');
			}
			
		}
		else
		{
			options = Object.extend(defaults, arguments[1] || {});

			if (!options.c)
			{
				alert('wrong');
				return ;
			}
		}


		options.x = Event.pointerY(event);
		options.y = Event.pointerX(event);

		this.addWindow(event, options);


		if (options.c)
		{
			this.processInfo(options.c, 't');
		}
		else
		{
			var matchUrl = new RegExp("^(http|https)://[A-Za-z0-9\./=\?%_~@#:;\+\-]*[\.]+(php|html|htm|jsp|py|pl)+$", "ig");
			if(matchUrl.test(elt.href))
			{
				this.processInfo('<div id="tooltip_loading"><img src="' + IMA_PATH + '/js/loading2.gif"/></div>', 't');
				this.loadInfo(elt.href, {option:{lbType:'t'}});
			}
			else
			{
				var msg = elt.getAttribute('msg');

				if (!msg)
				{
					msg = elt.getAttribute('title');
				}

				this.processInfo(msg, 't');		
			}

		}
	},

	/**
	 * 处理Tooltip 唯一.
	 *
	 * @access	public
	 */
	tagTS: function(ctrl)
	{
		var msg = ctrl.getAttribute('msg');

		if (!msg)
		{
			msg = ctrl.getAttribute('title');
			ctrl.setAttribute("msg", msg);
		}
		
		ctrl.title = '';
		
		Event.observe(ctrl, 'mouseover', this.doTagTS.bind(this), false);
		Event.observe(ctrl, 'mouseout', this.hideTagTS.bind(this), false);
		Event.observe(ctrl, 'mousemove', this.moveTagTS.bind(this), false);
		Event.observe(ctrl, 'blur', this.hideTagTS.bind(this), false);
		ctrl.onmouseover = this.empty;
		ctrl.onmouseout = this.empty;
		ctrl.onmousemove = this.empty;
		ctrl.onblur = this.empty;
		ctrl = null;
	},

	doTagTS : function(event)
	{
		if (this.ajaxId)
		{
			//return false;
		}

		var options = {};
		var elt = Event.element(event);

		if (!elt.hasClassName('TS'))
		{
			elt = elt.up('.TS');
		}

		try
		{
			var msg = elt.getAttribute('msg');

			if (!msg)
			{
				msg = elt.getAttribute('title');
			}
		}
		catch(e)
		{
			return false;
		}

		Position.prepare();
		$('tooltip_singleton_cts_text').update(msg);

		Element.show('tooltip_singleton');
//		if('undefined' != typeof(Effect))
//		{
//			if (this.tooltipSingleton[1])
//			{
//				this.tooltipSingleton[1].cancel(); 
//				this.tooltipSingleton[1] = null;
//			}
//
//			this.tooltipSingleton[0] = Effect.Appear($('tooltip_singleton'), {to: 0.95, from: 0.0});
//			//Effect.Appear('tooltip_singleton');
//		}
//		else
//		{
//			Element.show('tooltip_singleton');
//		}
		
		if (Prototype.Browser.IE)
		{
			//this.prepareIE('100%', 'hidden');
		}

		try
		{
			var func = elt.getAttribute('func');

			if (func)
			{
				eval(func + 'oe(elt);');
			}
		}
		catch(e)
		{
		}

		options = null;
		msg = null;
		elt = null;
	},

	moveTagTS : function(event)
	{
		var w = $('tooltip_singleton').getWidth();
		var h = $('tooltip_singleton').getHeight();

		//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		var arrayPageScroll = getPageSize();


		var wh = Event.pointerY(event) - Position.deltaY;
		var ww = Event.pointerX(event) - Position.deltaX;

		var k = 0;
		var g = 0;
		if (ww + w + 10 > arrayPageSize[2])
		{
			k = -w - 10;
		}
		else
		{
			k = 10;
		}

		if (wh + h + 35 > arrayPageSize[3])
		{
			g = -h - 10;
		}
		else
		{
			g = 10;
		}


		$('tooltip_singleton').style.top = (Event.pointerY(event) + g) + 'px';
		$('tooltip_singleton').style.left = (Event.pointerX(event) + k) + 'px';

		w = null;
		h = null;
		wh = null;
		ww = null;
		k = null;
		j = null;
	},

	hideTagTS : function(event)
	{
		Element.hide('tooltip_singleton');
//		if('undefined' != typeof(Effect))
//		{
//			if (this.tooltipSingleton[0])
//			{
//				this.tooltipSingleton[0].cancel(); 
//				this.tooltipSingleton[0] = null;
//			}
//
//			Element.hide('tooltip_singleton');
//			//this.tooltipSingleton[1] = Effect.Fade('tooltip_singleton');
//		}
//		else
//		{
//			Element.hide('tooltip_singleton');
//		}
		

		if (Prototype.Browser.IE)
		{
			//this.prepareIE('auto', 'auto');
		}

		//
		var elt = Event.element(event);

		if (!elt.hasClassName('TS'))
		{
			elt = elt.up('.TS');
		}

		try
		{
			var func = elt.getAttribute('func');

			if (func)
			{
				eval(func + 'ot(elt);');
			}
		}
		catch(e)
		{
		}

		elt = null;
	}
};

var	mask = new LightBox();

/**
 * 初始化.
 *
 * @access	public
 */
function initialize()
{
	var lbox = document.getElementsByClassName('O');

	for(i = 0; i < lbox.length; i++)
	{
		mask.tag(lbox[i]);
	}
	
	//处理tooltip
	lbox = document.getElementsByClassName('T');

	for(i = 0; i < lbox.length; i++)
	{
		mask.tagT(lbox[i]);
	}

	lbox = document.getElementsByClassName('TS');

	for(i = 0; i < lbox.length; i++)
	{
		mask.tagTS(lbox[i]);
	}

	try 
	{
		init();
	}
	catch(e)
	{}

	lbox = null;
};


Event.observe(window, 'load', initialize, false);

